<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/jsp/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title>menu content</title>
<%
	String menuId = request.getAttribute("menuId") == null ? "":request.getAttribute("menuId").toString();
	String message = request.getAttribute("message") == null ? "":request.getAttribute("message").toString();
	String parentId = request.getAttribute("parentId") == null ? "":request.getAttribute("parentId").toString();
	String isLeaf = request.getAttribute("isLeaf") == null ? "":request.getAttribute("isLeaf").toString();
	String styleFlag = request.getAttribute("styleFlag") == null ? "":request.getAttribute("styleFlag").toString();
	String url = request.getAttribute("url") == null ? "":request.getAttribute("url").toString();
	String menuname = request.getAttribute("menuname") == null ? "":request.getAttribute("menuname").toString();
	String treeShow = request.getAttribute("treeShow") == null ? "":request.getAttribute("treeShow").toString();
	String loadPage = request.getAttribute("loadPage") == null ? "":request.getAttribute("loadPage").toString();
	String opdata = request.getAttribute("opdata") == null ? "":request.getAttribute("opdata").toString();
	String link = request.getAttribute("link") == null ? "":request.getAttribute("link").toString();
	String level = request.getAttribute("level") == null ? "":request.getAttribute("level").toString();
	String root = request.getAttribute("root") == null ? menuId:request.getAttribute("root").toString();
	String rootId = request.getAttribute("rootId") == null ? menuId:request.getAttribute("rootId").toString();
	String rootName = request.getAttribute("rootName") == null ? menuname:request.getAttribute("rootName").toString();
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<link id="editCss" rel="stylesheet" type="text/css" href="<%=basePath %>css/style.css" />
<link id="rightCss" rel="stylesheet" type="text/css" href="<%=basePath %>css/right.css" />
<link id="dtreeCss" rel="stylesheet" type="text/css" href="<%=basePath %>css/dtree.css" />
<style>
html,body { height:100%; overflow:hidden;}
</style>
<script type="text/javascript">
	function toTarget(type,url){
		url = url + '&menuId=' + document.getElementById('menuId').value;
		url = url + '&parentId=' + document.getElementById('parentId').value;
		url = url + '&target=' + type;
		url = url + '&level=' + document.getElementById('level').value;
		url = url + '&root=' + document.getElementById('root').value;
		if(type == "delete"){
			if(confirm("你确定要删除吗?")){
				window.location.href = url;
			}
		} else {
			window.location.href = url;
		}
	}
	function submitForm(type,add){
		document.getElementById("opType").value=type;
		document.getElementById("addType").value=add;
		if(checkMenuName(add)) {
			document.menu.submit();
		}
	}
	function checkMenuName(addType){
		var name = document.getElementById('menuname').value;
		if(name == ""){
			alert('菜单名称不能为空!');
			return false;
		}
		//if(name.length > 8) {
		//	alert('字数不能超过8个!');
		//	return false;
		//}
		var level = document.getElementById('level').value;
		var styleFlag = document.getElementById('styleFlag').value;
		if(level >= 4) {
			if(addType == "0" && styleFlag == "1"){
				alert('增加同级菜单,必须为水平显示!');
				return false;
			} else if(addType == "1" && styleFlag == "0"){
				alert('增加下一级菜单,必须为竖直显示!');
				return false;
			}
		}
		return true;
	}
</script>
</head>
<body class="bgpic">
<div class="crumbs">
					当前位置：菜单管理 &gt; <%=link %>
</div>
<script type="text/javascript" src="<%=basePath %>js/menu_dtree.js"></script>
<div>
<table cellPadding="0" cellSpacing="0" border="0" width="100%" height="100%">
	<tr>
	<% if(!treeShow.equals("")) { %>
	  <td width="280px" valign="top" style=" _height:100%; bottom:0;">
		<div style="width:280px; position:absolute; top:26px; right:0px; left:0px; bottom:0px;  overflow: auto; height:94%; vertical-align: top;border: #8cb9cc 1px solid;  background-color:#FFF" id="treeDiv">
			<script type="text/javascript">
				var d = new dTree('d','<%=basePath %>',document);
				d.add("<%=rootId %>", -1, "<%=rootName %>","1","竖直显示"); 
			</script>
			
			<c:forEach items="${treeList}" var="tree" varStatus="i">
				<script type="text/javascript">
						d.add('${tree.menuId}','${tree.parentId}','${tree.menuName}','${tree.menuURL}');
				</script>
			</c:forEach>
			<script type="text/javascript">
					document.write("<br>"+d);
			</script>
		</div>
	  </td>
	 <%  }  %>
	  <td valign="top" height="100%" style="padding-left:5px">
		<div class="tableBox">
		  	<div class="search">
				<div class="tab">
					<span class="right"></span>
					<span class="font-blue14pxb">菜单管理</span>
				</div>
			</div>
		  <table cellPadding="0" cellSpacing="0" border="0" width="100%" bgcolor="#FFFFFF">
			<tr>
			  <th width="20%" class="text_right h">菜单名称</th>
			  <td class="text_left"><input style="width:90%" type="text" id="menuname" name="menuname" readonly value="<%=menuname %>"/></td>
			</tr>
			<tr>
			  <th class="text_right h">URL(请填写相对路径):</th>
			  <td class="text_left"><input style="width:90%" type="text" id="url" name="url" readonly value="<%=url %>"/></td>
			</tr>
			<tr>
				<th class="text_right h">
					<input type="hidden" id="opType" name="opType" value="0"/>
					<input type="hidden" id="addType" name="addType" value="0"/>
					<input type="hidden" id="level" name="level" value="<%=level %>"/>
					<input type="hidden" id="menuId" name="menuId" value="<%=menuId %>"/>
					<input type="hidden" id="parentId" name="parentId" value="<%=parentId %>"/>
					<input type="hidden" id="styleFlag" name="styleFlag" value="<%=styleFlag %>"/>
					<input type="hidden" id="root" name="root" value="<%=root %>"/>
					显示方式:
				</th>
				<td class="text_left">
					<% if(styleFlag.equals("") || styleFlag.equals("0")) { %>
						<input type="text" id="styleFlag1" name="styleFlag1" readonly value="水平显示"/>
					<% } else if(styleFlag.equals("1")) {  %>
						<input type="text" id="styleFlag1" name="styleFlag1" readonly value="竖直显示"/>	
					<% } %>
				</td>
			</tr>
			<!-- 
			<tr>
			  <th class="text_right h">是否为叶子节点:</th>
			  <td class="text_left">
		  		<% //if(isLeaf.equals("") || isLeaf.equals("1")) { %>
		  			<input type="hidden" id="isLeaf" name="isLeaf" readonly value="1"/>
					<input type="text" id="leaf" name="leaf" readonly value="是"/>
				<% //} else if(isLeaf.equals("0")) { %>
					<input type="hidden" id="isLeaf" name="isLeaf" readonly value="0"/>
					<input type="text" id="leaf" name="leaf" readonly value="否"/>
				<% //} %>
					
			  </td>
			</tr>
			 -->
			<tr class="footer">
				<td colspan="2" class="bgcolf">
					<input type="button" onclick="javaScript:toTarget('add','<%=basePath %>servlet/menu?opType=4&treeShow=<%=treeShow%>');" value="添加" class="button"/>
					<input type="button" onclick="javaScript:toTarget('modify','<%=basePath %>servlet/menu?opType=4');" value="修改" class="button"/>
					<input type="button" onclick="javaScript:toTarget('delete','<%=basePath %>servlet/menu?opType=2');" value="删除" class="button"/>
				</td>
			</tr>
			<tr>
				<td colspan="2" class="bgcolf"><%=message %></td>
			</tr>
		  </table>
		</div>
	  </td>
	</tr>
</table><br /><br /><br />
</div>
<% if(loadPage.equals("parent")) {%>
<script type="text/javascript">
    //window.parent.location.replace(window.parent.location.href);
 	  if("<%=opdata %>" == "add" ) {
	    var menu = window.parent.document.getElementById('toolsMenu');
	    menu.innerHTML += "<a class=\"menuItem\" href=\"javascript:void(0)\" id=\"a_<%=menuId %>\" "
	    			+ "onclick=\"javascript:clickTopMenu('<%=path%>/servlet/menu?opType=3&menuId=<%=menuId %>','<%=path%>/servlet/menu?opType=4&menuId=<%=menuId %>');\"><%=menuname %></a>";
    } else if("<%=opdata %>" == "delete") {
	    var node = window.parent.document.getElementById('a_<%=menuId %>');
	    node.parentNode.removeChild(node);
	    
    } else if("<%=opdata %>" == "modify") {
    	var node = window.parent.document.getElementById('a_<%=menuId %>');
    	node.innerHTML='<%=menuname %>';
    }
</script>
<% } else if(loadPage.equals("left")) {%>
<script type="text/javascript">
    var rootId = window.parent['leftIframe'].document.getElementById('root').value;
    window.parent.document.getElementById('leftIframe').src = '<%=basePath %>servlet/menu?opType=3&menuId=' + rootId;
</script>
<% } %>
</body>
</html>